package com.itheima.dome;

import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

public class InetAddressDemo {
    public static void main(String[] args) throws UnknownHostException, UnsupportedEncodingException {
        InetAddress byName = InetAddress.getByName("10.254.1.220");
        System.out.println(byName);
        System.out.println(byName.getHostName());
        System.out.println(byName.getHostAddress());
        System.out.println("---------------------");
        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println(localHost);
        String hostAddress = localHost.getHostAddress();
        System.out.println(hostAddress);
        String hostName = localHost.getHostName();
        System.out.println(hostName);
        byte[] address = localHost.getAddress();
        String s = Arrays.toString(address);
        System.out.println(s);

        //String s1 = new String(address,0,address.length,"GBK");
        //System.out.println(s1);
    }
}
